package com.zrf.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.zrf.dao.impl.ProductDaoImpl;
import com.zrf.dao.impl.SellerDaoImpl;
import com.zrf.hibernate.model.PageBean;
import com.zrf.hibernate.pojo.Product;
import com.zrf.hibernate.pojo.Seller;
import com.zrf.tool.Tools;

@Service("sellerService")
public class SellerService {

	@Autowired
	private SellerDaoImpl sdi = null;
	@Autowired
	private ProductDaoImpl pdi = null;
	
	
	public Seller getSeller(String name){
		return sdi.getSellerByName(name);
	}
	
	public Integer getId(){
		List<?> list = pdi.getAllId();
		return Tools.getListID(list);
	}
	
	
	
	public Product findProductById(Integer id){
		try {
			return pdi.findById(id);
		} catch (Exception e) {
			e.printStackTrace();
			// TODO: handle exception
		}
		return null;
	}
	
	
	
	public Long getNumBySeller(String name){
		Long num = 0l;
		num = pdi.getNumBySName(name);
		return num;
	}
	
	public List<?> getProductByName(String name,PageBean pagebean){
		return pdi.getProductByName(name, pagebean);
	}
	
	
	public boolean addProduct(Product p){
		try {
			pdi.addProduct(p);
			return true;
		} catch (Exception e) {
			e.printStackTrace();
			// TODO: handle exception
		}
		return false;
	}
	
	public boolean deleteProduct(Integer id){
		try {
			pdi.deleteById(id);
			return true;
		} catch (Exception e) {
			e.printStackTrace();
			// TODO: handle exception
		}
		return false;
	}
	
	public boolean updateProduct(Product p){
		try {
			pdi.updateProduct(p);
			return true;
		} catch (Exception e) {
			e.printStackTrace();
			// TODO: handle exception
		}
		return false;
	}
}
